home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / cmln0985.arc / PARSER.BAS < prev    next >
BASIC Source File  |  1986-02-27  |  1KB  |  19 lines

  1. 1000 ' ===================A TINY BASIC PARSER==============================
  2. 1010 ' (technically, a "finite automaton" accepter for regular expressions)
  3. 1020 '
  4. 1030 ' Direct comments, questions, abuse to:
  5. 1040 '    David Ross, Dept. of Math., Univ. of Iowa, Iowa City, IA 52242
  6. 1050 '                
  7. 1060 ' See PARSER.DOC for a more complete explanation of this program
  8. 1070 ' 
  9. 1080 ' Routine assumes that arrays NN$, ND, and CD$ are defined already
  10. 1090 '
  11. 1100 CN=0:OUTSTR$=""            'Start at node 0; init. output string
  12. 1110 L=LEN(NN$(CN)):IF L=0 THEN RETURN    'If CurrentNode is terminal, quit
  13. 1120 CH$=INPUT$(1):I=0            'Read a ch$; init. "NextNode" pointer 
  14. 1130 I=I+1: IF I>L THEN  1120        'Tried all NextNodes? Then ignore ch$ 
  15. 1140 IF INSTR(CD$(ND(ASC(MID$(NN$(CN),I)))),CH$)=0 THEN 1130
  16. 1150 ' Is ch$ in the "acceptable" list for NextNode # I ? If not, try I+1
  17. 1160 OUTSTR$=OUTSTR$+CH$:PRINT CH$;    ' *Is* on I's list; accept ch$...
  18. 1170 CN=ASC(MID$(NN$(CN),I)):GOTO 1110    ' ...and make NextNode CurrentNode
  19. $+CH$:PRINT CH$;